package com.wifi.eshipewifi;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wifi.BaseApplication;

public class PayActivity extends AppCompatActivity implements View.OnClickListener {
    BaseApplication application;
    TextView tv_include_tittle;
    ImageButton ib_back;
    LinearLayout ll_phone;
    LinearLayout ll_wechat;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay);

        //每个activity都要加这一句
        application = (BaseApplication) getApplication();

        tv_include_tittle = (TextView) findViewById(R.id.tv_include_tittle);
        ib_back = (ImageButton) findViewById(R.id.ib_back);
        ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        ll_wechat = (LinearLayout) findViewById(R.id.ll_wechat);
        tv_include_tittle.setText("充值");
        ib_back.setOnClickListener(this);
        ll_phone.setOnClickListener(this);
        ll_wechat.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_back:
                this.finish();
                break;

            case R.id.ll_phone:
                Intent dialIntent =  new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + 110));//跳转到拨号界面，同时传递电话号码
                startActivity(dialIntent);
                break;

            case R.id.ll_wechat:
                final View view = View.inflate(this, R.layout.item_dialog_cz_text, null);
                AlertDialog dialog= new AlertDialog.Builder(this)
                        .setTitle("微信公众号")
                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setView(view)
                        .setPositiveButton("确定复制", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                // 将文本内容放到系统剪贴板里。
                                cm.setText("123456");
                                application.makeToast(PayActivity.this,"复制成功，可以发给朋友们了。",true);
                                dialog.cancel();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }).create();
                dialog .show();
                break;

        }
    }
}
